﻿#include "view.h"
int Menu() {
	//创建850*650的画布
	initgraph(850, 650);
	//显示 
	IMAGE loge_img;
	loadimage(&loge_img, _T("loge.bmp"), 650, 200);
	putimage(100, 50, &loge_img);

	//按钮
	setlinecolor(WHITE);
	setfillcolor(BLACK);

	fillrectangle(350, 250, 500, 300);
	settextstyle(30, 0, _T("宋体"));
	outtextxy(365, 260, _T("开始游戏"));
	
	fillrectangle(350, 350, 500, 400);
	outtextxy(385, 360, _T("设 置"));

	fillrectangle(350, 450, 500, 500);
	outtextxy(365, 460, _T("退出游戏"));


	MOUSEMSG mouse;

	//int fin = 0;
	while (1) {
		mouse = GetMouseMsg();
		switch (mouse.uMsg) {
		case WM_MOUSEMOVE:
			if (mouse.x > 350 && mouse.x < 500 && mouse.y>250 && mouse.y < 300) {
				settextcolor(RED);
				outtextxy(365, 260, _T("开始游戏"));
			}
			else {
				settextcolor(WHITE);
				outtextxy(365, 260, _T("开始游戏"));
			}

			if (mouse.x > 350 && mouse.x < 500 && mouse.y>350 && mouse.y < 400) {
				settextcolor(RED);
				outtextxy(385, 360, _T("设 置"));
			}
			else {
				settextcolor(WHITE);
				outtextxy(385, 360, _T("设 置"));
			}


			if (mouse.x > 350 && mouse.x < 500 && mouse.y>450 && mouse.y < 500) {
				settextcolor(RED);
				outtextxy(365, 460, _T("退出游戏"));
			}
			else {
				settextcolor(WHITE);
				outtextxy(365, 460, _T("退出游戏"));
			}
			break;

		case WM_LBUTTONDOWN:
			if (mouse.x > 350 && mouse.x < 500 && mouse.y>250 && mouse.y < 300) {
				cleardevice();
				return 1;
			}
			if (mouse.x > 350 && mouse.x < 500 && mouse.y>350 && mouse.y < 400) {
				cleardevice();
				return 2;
			}
			if (mouse.x > 350 && mouse.x < 500 && mouse.y>450 && mouse.y < 500) {
				closegraph();
			}

		}
	}
	return 0;
}

int ViewSelect(int &Level) {
	//显示logo
	IMAGE loge_img;
	loadimage(&loge_img, _T("loge.bmp"), 650, 200);
	putimage(100, 50, &loge_img);

	//实现导航按钮
	setlinecolor(WHITE);
	setfillcolor(BLACK);

	settextstyle(30, 0, _T("宋体"));
	settextcolor(WHITE);

	fillrectangle(350, 300, 500, 340);
	outtextxy(365, 310, _T("经典模式"));

	fillrectangle(350, 370, 500, 410);
	outtextxy(365, 380, _T("无尽模式"));

	fillrectangle(350, 440, 500, 480);
	outtextxy(365, 450, _T("双机模式"));

	fillrectangle(350, 510, 500, 550);
	outtextxy(365, 520, _T("返回首页"));

	MOUSEMSG mouse;

	while (1) {
		mouse = GetMouseMsg();

		switch (mouse.uMsg) {
		case WM_MOUSEMOVE:
			if ((mouse.x > 350 && mouse.x < 500) && (mouse.y > 300 && mouse.y < 340)) {
				settextcolor(RED);
				outtextxy(365, 310, _T("经典模式"));
			}
			else {
				settextcolor(WHITE);
				outtextxy(365, 310, _T("经典模式"));
			}
			if ((mouse.x > 350 && mouse.x < 500) && (mouse.y > 370 && mouse.y < 410)) {
				settextcolor(RED);
				outtextxy(365, 380, _T("无尽模式"));
			}
			else {
				settextcolor(WHITE);
				outtextxy(365, 380, _T("无尽模式"));
			}
			if ((mouse.x > 350 && mouse.x < 500) && (mouse.y > 440 && mouse.y < 480)) {
				settextcolor(RED);
				outtextxy(365, 450, _T("双机模式"));
			}
			else {
				settextcolor(WHITE);
				outtextxy(365, 450, _T("双机模式"));
			}
			if ((mouse.x > 350 && mouse.x < 500) && (mouse.y > 510 && mouse.y < 550)) {
				settextcolor(RED);
				outtextxy(365, 520, _T("返回首页"));
			}
			else {
				settextcolor(WHITE);
				outtextxy(365, 520, _T("返回首页"));
			}
			break;

		case WM_LBUTTONDOWN:
			if ((mouse.x > 350 && mouse.x < 500) && (mouse.y > 300 && mouse.y < 340)) {
				wchar_t s[10];
				InputBox(s, 10, L"请输入关卡数（1-5）", L"关卡选择");
				Level = _wtoi(s);
				cleardevice();
				return 1;
			}
			if ((mouse.x > 350 && mouse.x < 500) && (mouse.y > 370 && mouse.y < 410)) {
				cleardevice();
				return 2;
			}
			if ((mouse.x > 350 && mouse.x < 500) && (mouse.y > 440 && mouse.y < 480)) {
				cleardevice();
				return 3;
			}
			if ((mouse.x > 350 && mouse.x < 500) && (mouse.y > 510 && mouse.y < 550)) {
				cleardevice();
				return 0;
			}
		}
	}
	return 0;
}

int ViewGame(int Model, int &Level) {
	int map[26][26];
	UserTank user(3, 1, 1, Up, 24, 9);//我方坦克初始化
	EnemyTank enemytank(Down, 1, 18);//敌方坦克初始化

	//step用于判断前进还是转向
	int step;
	int step_e;

	//子弹初始化
	Bullets bullet, bullet_e;
	bullet.status = 0;//子弹状态,用于判断子弹是否处于发射状态,0代表可发射，1代表不能发射
	bullet_e.status = 0;

	Init(Level, map);

	setlinecolor(WHITE);
	setfillcolor(BLACK);
	fillrectangle(99, -1, 751, 651);
	fillrectangle(10, 100, 90, 150);
	fillrectangle(10, 200, 90, 250);

	//说明按钮
	IMAGE img1;
	loadimage(&img1, _T("illustrate.bmp"), 98, 155);
	putimage(0, 380, &img1);
	line(750, 325, 850, 325);
	line(0, 325, 100, 325);
	settextstyle(30, 0, _T("宋体"));
	outtextxy(20, 110, _T("暂停"));
	outtextxy(20, 210, _T("结束"));

	//地图
	IMAGE img_map[10];
	loadimage(img_map + 1, _T("wall2.jpg"), 25, 25);
	loadimage(img_map + 2, _T("wall1.jpg"), 25, 25);
	loadimage(img_map + 3, _T("grass.png"), 25, 25);
	loadimage(img_map + 4, _T("water.png"), 25, 25);
	loadimage(img_map + 5, _T("home.jpg"), 50, 50);
	loadimage(img_map + 6, _T("tank_up.jpg"), 50, 50);
	loadimage(img_map + 7, _T("enemy_tank_left.jpg"), 50, 50);
	loadimage(img_map + 8, _T("wall2.jpg"), 25, 25);
	if (Level < 3) {
		//加载家和坦克图片
		putimage(325, 600, img_map + 6);
		putimage(400, 600, img_map + 5);
	}
	//我方坦克方向
	IMAGE img_usertank[4];
	loadimage(img_usertank, _T("tank_up.jpg"), 50, 50);
	loadimage(img_usertank + 1, _T("tank_down.jpg"), 50, 50);
	loadimage(img_usertank + 2, _T("tank_left.jpg"), 50, 50);
	loadimage(img_usertank + 3, _T("tank_right.jpg"), 50, 50);
	//敌方坦克
	IMAGE img_enemytank[4];
	loadimage(img_enemytank, _T("enemy_tank_up.jpg"), 50, 50);
	loadimage(img_enemytank + 1, _T("enemy_tank_down.jpg"), 50, 50);
	loadimage(img_enemytank + 2, _T("enemy_tank_left.jpg"), 50, 50);
	loadimage(img_enemytank + 3, _T("enemy_tank_right.jpg"), 50, 50);
	int num = 0;

	settextstyle(20, 0, _T("宋体"));
	settextcolor(RED);
	outtextxy(760, 80, _T("敌方坦克"));
	settextcolor(YELLOW);
	outtextxy(760, 400, _T("我方坦克"));

	//地图生成一次,但坦克移动后会消除相应的图片
	/*for (int i = 0; i < 26; i++)
		for (int j = 0; j < 26; j++) {
			switch (map[i][j]) {
			case 1:
				putimage((100 + 25 * j), 25 * i, img_map + 1);
				break;
			case 2:
				putimage((100 + 25 * j), 25 * i, img_map + 2);
				break;
			case 3:
				putimage((100 + 25 * j), 25 * i, img_map + 3);
				break;
			case 4:
				putimage((100 + 25 * j), 25 * i, img_map + 4);
				break;
			case 8:
				putimage((100 + 25 * j), 25 * i, img_map + 8);
				break;
			default:
				break;
			}
		}*/
	while (1) {
		int ret = 0;
		//地图生成一次,但坦克移动后会消除相应的图片
		for (int i = 0; i < 26; i++)
			for (int j = 0; j < 26; j++) {
				switch (map[i][j]) {
				case 1:
					putimage((100 + 25 * j), 25 * i, img_map + 1);
					break;
				case 2:
					putimage((100 + 25 * j), 25 * i, img_map + 2);
					break;
				case 3:
					putimage((100 + 25 * j), 25 * i, img_map + 3);
					break;
				case 4:
					putimage((100 + 25 * j), 25 * i, img_map + 4);
					break;
				case 8:
					putimage((100 + 25 * j), 25 * i, img_map + 8);
					break;
				default:
					break;
				}
			}
		//敌方信息
		settextcolor(RED);
		int x = 20;
		TCHAR s[10];
		_stprintf(s, _T("剩余：%d"), x);

		outtextxy(760, 110, s);
		int x1 = 15;
		TCHAR s1[10];
		_stprintf(s1, _T("LV1：%d"), x1);
		outtextxy(760, 140, s1);
		int x2 = 4;
		TCHAR s2[10];
		_stprintf(s2, _T("LV2：%d"), x2);
		outtextxy(760, 170, s2);
		int x3 = 1;
		TCHAR s3[10];
		_stprintf(s3, _T("LV1：%d"), x3);
		outtextxy(760, 200, s3);

		//我方信息
		settextcolor(YELLOW);
		TCHAR t1[10];
		_stprintf(t1, _T("生命：%d"), user.life);
		outtextxy(760, 430, t1);
		TCHAR t2[10];
		_stprintf(t2, _T("火力：%d"), user.bullet);
		outtextxy(760, 460, t2);
		TCHAR t3[10];
		_stprintf(t3, _T("速度：%d"), user.speed);
		outtextxy(760, 490, t3);

		//暂停与结束会变卡
		/*while (1) {
			settextstyle(30, 0, _T("宋体"));
			MOUSEMSG mouse1 = GetMouseMsg();
			switch (mouse1.uMsg) {
			case WM_MOUSEMOVE:
				if (mouse1.x > 10 && mouse1.x < 90 && mouse1.y>100 && mouse1.y < 150) {
					settextcolor(BLUE);
					outtextxy(20, 110, _T("暂停"));
				}
				else {
					settextcolor(WHITE);
					outtextxy(20, 110, _T("暂停"));
				}
				if (mouse1.x > 10 && mouse1.x < 90 && mouse1.y>200 && mouse1.y < 250) {
					settextcolor(BLUE);
					outtextxy(20, 210, _T("结束"));
				}
				else {
					settextcolor(WHITE);
					outtextxy(20, 210, _T("结束"));
				}
				break;
			case WM_LBUTTONDOWN:
				if (mouse1.x > 10 && mouse1.x < 90 && mouse1.y>100 && mouse1.y < 150) {
					settextcolor(RED);
					outtextxy(20, 110, _T("继续"));
					while (1) {
						MOUSEMSG mouse2 = GetMouseMsg();
						if (mouse2.uMsg == WM_LBUTTONDOWN)
							if (mouse2.x > 10 && mouse2.x < 90 && mouse2.y>100 && mouse2.y < 150) {
								outtextxy(20, 110, _T("暂停"));
								break;
							}
						else if (mouse2.x > 10 && mouse2.x < 90 && mouse2.y>200 && mouse2.y < 250)
							return -1;
					}
				}
				if (mouse1.x > 10 && mouse1.x < 90 && mouse1.y>200 && mouse1.y < 250)
						return -1;
				break;
			}
			break;
		}*/
		/*Direction dir = ShiftDirection();
		if (user.move(dir, map) == 1)
			switch (dir) {
			case Up:
				clearrectangle(100 + user.pos_y * 25, user.pos_x * 25, (user.pos_y) * 25 + 150, (user.pos_x) * 25 + 50);
				user.pos_x--;
				putimage(100 + user.pos_y * 25, user.pos_x * 25, img_usertank);
				break;
			case Down:
				clearrectangle(100 + user.pos_y * 25, user.pos_x * 25, user.pos_y * 25 + 150, user.pos_x * 25 + 50);
				user.pos_x++;
				putimage(100 + user.pos_y * 25, user.pos_x * 25, img_usertank + 1);
				break;
			case Left:
				clearrectangle(100 + user.pos_y * 25, user.pos_x * 25, user.pos_y * 25 + 150, user.pos_x * 25 + 50);
				user.pos_y--;
				putimage(100 + user.pos_y * 25, user.pos_x * 25, img_usertank + 2);
				break;
			case Right:
				clearrectangle(100 + user.pos_y * 25, user.pos_x * 25, user.pos_y * 25 + 150, user.pos_x * 25 + 50);
				user.pos_y++;
				putimage(100 + user.pos_y * 25, user.pos_x * 25, img_usertank + 3);
				break;
			}*/
			//敌方坦克自动移动操作
		num++;
		if (Level < 3) {
			if (num % 10 == 0) {
				switch (automatic(&enemytank)) {
				case's'://下
				case'S':
				{    //向前移动
					if (enemytank.dir == Down && ((map[enemytank.pos_x + 1][enemytank.pos_y] == 0 && map[enemytank.pos_x + 1][enemytank.pos_y - 1] == 0) || (map[enemytank.pos_x + 1][enemytank.pos_y] == 3 && map[enemytank.pos_x + 1][enemytank.pos_y - 1] == 3) ||
						(map[enemytank.pos_x + 1][enemytank.pos_y] == 3 && map[enemytank.pos_x + 1][enemytank.pos_y - 1] == 0) || (map[enemytank.pos_x + 1][enemytank.pos_y] == 0 && map[enemytank.pos_x + 1][enemytank.pos_y - 1] == 3)) && (enemytank.pos_x + 1) < 26) {
						step_e = 1;
						move_e(&enemytank, Down, img_enemytank + 1, step_e);
						enemytank.pos_x += 1;
						enemytank.dir = Down;

					}//转向
					else if (enemytank.dir != Down) {
						step_e = 0;
						pointswitch_e(&enemytank, Down);
						move_e(&enemytank, Down, img_enemytank + 1, step_e);
						enemytank.dir = Down;
					}
				}
				break;
				case'w'://上
				case'W':
				{
					if (enemytank.dir == Up && ((map[enemytank.pos_x - 1][enemytank.pos_y] == 0 && map[enemytank.pos_x - 1][enemytank.pos_y + 1] == 0) || (map[enemytank.pos_x - 1][enemytank.pos_y] == 3 && map[enemytank.pos_x - 1][enemytank.pos_y + 1] == 3) ||
						(map[enemytank.pos_x - 1][enemytank.pos_y] == 0 && map[enemytank.pos_x - 1][enemytank.pos_y + 1] == 3) || (map[enemytank.pos_x - 1][enemytank.pos_y] == 3 && map[enemytank.pos_x - 1][enemytank.pos_y + 1] == 0)) && (enemytank.pos_x - 1) >= 0) {
						step_e = 1;
						move_e(&enemytank, Up, img_enemytank, step_e);
						enemytank.pos_x -= 1;
						enemytank.dir = Up;
					}//转向
					else if (enemytank.dir != Up) {
						step_e = 0;
						pointswitch_e(&enemytank, Up);
						move_e(&enemytank, Up, img_enemytank, step_e);
						enemytank.dir = Up;
					}
				}
				break;
				case'a'://左
				case'A':
				{
					if (enemytank.dir == Left && ((map[enemytank.pos_x][enemytank.pos_y - 1] == 0 && map[enemytank.pos_x - 1][enemytank.pos_y - 1] == 0) || (map[enemytank.pos_x][enemytank.pos_y - 1] == 3 && map[enemytank.pos_x - 1][enemytank.pos_y - 1] == 3) ||
						(map[enemytank.pos_x][enemytank.pos_y - 1] == 3 && map[enemytank.pos_x - 1][enemytank.pos_y - 1] == 0) || (map[enemytank.pos_x][enemytank.pos_y - 1] == 0 && map[enemytank.pos_x - 1][enemytank.pos_y - 1] == 3)) && (enemytank.pos_y - 1) >= 0) {
						step_e = 1;
						move_e(&enemytank, Left, img_enemytank + 2, step_e);
						enemytank.pos_y -= 1;
						enemytank.dir = Left;
					}//转向
					else if (enemytank.dir != Left) {
						step_e = 0;
						pointswitch_e(&enemytank, Left);
						move_e(&enemytank, Left, img_enemytank + 2, step_e);
						enemytank.dir = Left;
					}
				}
				break;
				case'd'://右
				case'D':
				{
					if (enemytank.dir == Right && ((map[enemytank.pos_x][enemytank.pos_y + 1] == 0 && map[enemytank.pos_x + 1][enemytank.pos_y + 1] == 0) || (map[enemytank.pos_x][enemytank.pos_y + 1] == 3 && map[enemytank.pos_x + 1][enemytank.pos_y + 1] == 3) ||
						(map[enemytank.pos_x][enemytank.pos_y + 1] == 3 && map[enemytank.pos_x + 1][enemytank.pos_y + 1] == 0) || (map[enemytank.pos_x][enemytank.pos_y + 1] == 0 && map[enemytank.pos_x + 1][enemytank.pos_y + 1] == 3)) && (enemytank.pos_y + 1) < 26) {
						step_e = 1;
						move_e(&enemytank, Right, img_enemytank + 3, step_e);
						enemytank.pos_y += 1;
						enemytank.dir = Right;
					}//转向
					else if (enemytank.dir != Right) {
						step_e = 0;
						pointswitch_e(&enemytank, Right);
						move_e(&enemytank, Right, img_enemytank + 3, step_e);
						enemytank.dir = Right;
					}
				}
				break;
				case 'p':
				{
					if (bullet_e.status == 0) {
						if (enemytank.dir == Up) {
							bullet_e.pos_x = enemytank.pos_x * 25 - 4;
							bullet_e.pos_y = (enemytank.pos_y + 1) * 25 + 100 - 2;
							bullet_e.dir = enemytank.dir;
						}
						else if (enemytank.dir == Down) {
							bullet_e.pos_x = (enemytank.pos_x + 1) * 25;
							bullet_e.pos_y = (enemytank.pos_y) * 25 + 100 - 2;
							bullet_e.dir = enemytank.dir;
						}
						else if (enemytank.dir == Left) {
							bullet_e.pos_x = enemytank.pos_x * 25 - 2;
							bullet_e.pos_y = (enemytank.pos_y) * 25 + 100 - 4;
							bullet_e.dir = enemytank.dir;
						}
						else if (enemytank.dir == Right) {
							bullet_e.pos_x = (enemytank.pos_x + 1) * 25 - 2;
							bullet_e.pos_y = (enemytank.pos_y + 1) * 25 + 100;
							bullet_e.dir = enemytank.dir;
						}
					}
					bullet_e.status = 1;
				}
				break;
				}
			}
		}

		if (bullet_e.status == 1) {
			ret = shoot(&bullet_e, map, 1, &user, &enemytank);
		}
		Sleep(10);
		//我方坦克移动
		if (_kbhit()) {
			char key = _getch();
			//switch (automatic(&enemytank))
			switch (key) {
			case's'://下
			case'S':
			{    //向前移动
				if (user.dir == Down && ((map[user.pos_x + 1][user.pos_y] == 0 && map[user.pos_x + 1][user.pos_y - 1] == 0) || (map[user.pos_x + 1][user.pos_y] == 3 && map[user.pos_x + 1][user.pos_y - 1] == 3) || (map[user.pos_x + 1][user.pos_y] == 3 && map[user.pos_x + 1][user.pos_y - 1] == 0) || (map[user.pos_x + 1][user.pos_y] == 0 && map[user.pos_x + 1][user.pos_y - 1] == 3)) && (user.pos_x + 1) < 26) {
					step = 1;
					move(&user, Down, img_usertank + 1, step);
					user.pos_x += 1;
					user.dir = Down;
				}//转向
				else if (user.dir != Down) {
					step = 0;
					pointswitch(&user, Down);
					move(&user, Down, img_usertank + 1, step);
					user.dir = Down;
				}
			}
			break;
			case'w'://上
			case'W':
			{
				if (user.dir == Up && ((map[user.pos_x - 1][user.pos_y] == 0 && map[user.pos_x - 1][user.pos_y + 1] == 0) || (map[user.pos_x - 1][user.pos_y] == 3 && map[user.pos_x - 1][user.pos_y + 1] == 3) || (map[user.pos_x - 1][user.pos_y] == 0 && map[user.pos_x - 1][user.pos_y + 1] == 3) || (map[user.pos_x - 1][user.pos_y] == 3 && map[user.pos_x - 1][user.pos_y + 1] == 0)) && (user.pos_x - 1) >= 0) {
					step = 1;
					move(&user, Up, img_usertank, step);
					user.pos_x -= 1;
					user.dir = Up;
				}
				else if (user.dir != Up) {
					step = 0;
					pointswitch(&user, Up);
					move(&user, Up, img_usertank, step);
					user.dir = Up;
				}
			}
			break;
			case'a'://左
			case'A':
			{
				if (user.dir == Left && ((map[user.pos_x][user.pos_y - 1] == 0 && map[user.pos_x - 1][user.pos_y - 1] == 0) || (map[user.pos_x][user.pos_y - 1] == 3 && map[user.pos_x - 1][user.pos_y - 1] == 3) || (map[user.pos_x][user.pos_y - 1] == 3 && map[user.pos_x - 1][user.pos_y - 1] == 0) || (map[user.pos_x][user.pos_y - 1] == 0 && map[user.pos_x - 1][user.pos_y - 1] == 3)) && (user.pos_y - 1) >= 0) {
					step = 1;
					move(&user, Left, img_usertank + 2, step);
					user.pos_y -= 1;
					user.dir = Left;
				}
				else if (user.dir != Left) {
					step = 0;
					pointswitch(&user, Left);
					move(&user, Left, img_usertank + 2, step);
					user.dir = Left;
				}
			}
			break;
			case'd'://右
			case'D':
			{
				if (user.dir == Right && ((map[user.pos_x][user.pos_y + 1] == 0 && map[user.pos_x + 1][user.pos_y + 1] == 0) || (map[user.pos_x][user.pos_y + 1] == 3 && map[user.pos_x + 1][user.pos_y + 1] == 3) || (map[user.pos_x][user.pos_y + 1] == 3 && map[user.pos_x + 1][user.pos_y + 1] == 0) || (map[user.pos_x][user.pos_y + 1] == 0 && map[user.pos_x + 1][user.pos_y + 1] == 3)) && (user.pos_y + 1) < 26) {
					step = 1;
					move(&user, Right, img_usertank + 3, step);
					user.pos_y += 1;
					user.dir = Right;
				}
				else if (user.dir != Right) {
					step = 0;
					pointswitch(&user, Right);
					move(&user, Right, img_usertank + 3, step);
					user.dir = Right;
				}
			}
			break;
			case 'p'://开火
			case 'J':
			case 'j':
			case'P':
			{
				if (bullet.status == 0) {
					if (user.dir == Up) {
						bullet.pos_x = user.pos_x * 25 - 4;
						bullet.pos_y = (user.pos_y + 1) * 25 + 100 - 2;
						bullet.dir = user.dir;
					}
					else if (user.dir == Down) {
						bullet.pos_x = (user.pos_x + 1) * 25;
						bullet.pos_y = (user.pos_y) * 25 + 100 - 2;
						bullet.dir = user.dir;
					}
					else if (user.dir == Left) {
						bullet.pos_x = user.pos_x * 25 - 2;
						bullet.pos_y = (user.pos_y) * 25 + 100 - 4;
						bullet.dir = user.dir;
					}
					else if (user.dir == Right) {
						bullet.pos_x = (user.pos_x + 1) * 25 - 2;
						bullet.pos_y = (user.pos_y + 1) * 25 + 100;
						bullet.dir = user.dir;
					}
				}
				bullet.status = 1;
			}
			break;
			}
		}
		else {
			if (bullet.status == 1) {
				ret = shoot(&bullet, map, 0, &user, &enemytank);
			}
			Sleep(10);
		}
		Sleep(10);
		if (ret == -1)
			return 0;
		else if (ret == 1)
			return 1;
	}
	return -1;
}

int ViewOver(int over) {
	//回到首页
	if (over == -1)
		return -1;
	IMAGE over_img[2];
	//可适当修改参数
	loadimage(over_img, _T("failure.jpg"), 400, 150);
	loadimage(over_img + 1, _T("success.jpg"), 400, 150);
	clearrectangle(125, 175, 625, 475);

	setlinecolor(WHITE);
	setfillcolor(BLACK);
	settextstyle(25, 0, _T("宋体"));
	settextcolor(WHITE);
	fillrectangle(275, 400, 400, 440);
	fillrectangle(450, 400, 575, 440);

	//失败
	if (over == 0) {
		putimage(225, 225, over_img);
		outtextxy(287.5, 410, _T("重新开始"));
		outtextxy(462.5, 410, _T("回到首页"));
		MOUSEMSG mouse;
		while (1) {
			mouse = GetMouseMsg();
			switch (mouse.uMsg) {
			case WM_MOUSEMOVE:
				if ((mouse.x > 275 && mouse.x < 400) && (mouse.y > 400 && mouse.y < 440)) {
					settextcolor(RED);
					outtextxy(287.5, 410, _T("重新开始"));
				}
				else {
					settextcolor(WHITE);
					outtextxy(287.5, 410, _T("重新开始"));
				}
				if ((mouse.x > 450 && mouse.x < 575) && (mouse.y > 400 && mouse.y < 440)) {
					settextcolor(RED);
					outtextxy(462.5, 410, _T("回到首页"));
				}
				else {
					settextcolor(WHITE);
					outtextxy(462.5, 410, _T("回到首页"));
				}
				break;
			case WM_LBUTTONDOWN:
				if ((mouse.x > 275 && mouse.x < 400) && (mouse.y > 400 && mouse.y < 440))
					return 0;
				if ((mouse.x > 450 && mouse.x < 575) && (mouse.y > 400 && mouse.y < 440))
					return -1;
				return 0;
			}
		}
	}
	//成功
	if (over == 1) {
		putimage(225, 225, over_img + 1);
		outtextxy(290, 410, _T("下一关"));
		outtextxy(462.5, 410, _T("回到首页"));
		MOUSEMSG mouse;
		while (1) {
			mouse = GetMouseMsg();
			switch (mouse.uMsg) {
			case WM_MOUSEMOVE:
				if ((mouse.x > 275 && mouse.x < 400) && (mouse.y > 400 && mouse.y < 440)) {
					settextcolor(RED);
					outtextxy(290, 410, _T("下一关"));
				}
				else {
					settextcolor(WHITE);
					outtextxy(290, 410, _T("下一关"));
				}
				if ((mouse.x > 450 && mouse.x < 575) && (mouse.y > 400 && mouse.y < 440)) {
					settextcolor(RED);
					outtextxy(462.5, 410, _T("回到首页"));
				}
				else {
					settextcolor(WHITE);
					outtextxy(462.5, 410, _T("回到首页"));
				}
				break;
			case WM_LBUTTONDOWN:
				if ((mouse.x > 275 && mouse.x < 400) && (mouse.y > 400 && mouse.y < 440))
					return 1;
				if ((mouse.x > 450 && mouse.x < 575) && (mouse.y > 400 && mouse.y < 440))
					return -1;
				return 1;
				break;
			}
		}
	}
	return -1;
}